from myelin.Ns import MYELINS

from nodetypes.ntypes.Document.view.MML import Document, Transform


class Document(Document):
    
    def createContent(self, context, node, locale):
        self.createFileContent(
            context,
            node.xml_append(
                node.xml_create_element(
                    u'a:dict', MYELINS,
                    attributes = {
                        u'key'      : u'file-metadata',
                    }
                )
            )
        )
        return super(Document, self).createContent(context, node, locale)
    
    def createFileContent(self, context, node):
        for s in context.model.dcSource:
            print "SOURCE: %s" % s.rdf_value
            print "        %s" % s.rdf_getDomain()
            node.xml_append(
                node.xml_create_element(
                    u'a:entry', MYELINS,
                    attributes = {
                        u'key'      : u'format',
                    },
                    content = s.rdf_join('dcFormat')
                )
            )
            #node.xml_append(
            #    node.xml_create_element(
            #        u'a:entry', MYELINS,
            #        attributes = {
            #            u'key'      : u'source',
            #        },
            #        content = context.uriMapper.apply(s.rdf_domain)
            #    )
            #)
            
        return node


class Transform(Transform):
    
    newDocument = Document